package model

import (
	"encoding/json"
	"github.com/xfchenjian/gossdb"
	"log"
	"os"
)

var uidIndexKey string = "uid_index"
var ChannelPrefix string = "channel_"
var accountDB string = "account"
var uid_index = 10086

var SSDBPool, _ = gossdb.NewPool(&gossdb.Config{
	Host:             "127.0.0.1",
	Port:             8888,
	MinPoolSize:      10,
	MaxPoolSize:      50,
	AcquireIncrement: 5,
})

func init() {
	client, err := SSDBPool.NewClient()
	if err != nil {
		log.Fatal(err.Error())
		os.Exit(-1)
	}

	exist, err := client.Exists(uidIndexKey)
	if err != nil {
		log.Fatal(err.Error())
		os.Exit(-1)
	}

	if !exist {
		client.Set(uidIndexKey, uid_index)
	}
}

func toJson(val interface{}) string {
	buff, err := json.Marshal(val)
	if err != nil {
		log.Fatalf("%v json encode fail, err: %s", val, err.Error())
		return string("")
	}

	return string(buff)
}
